<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config='tableToolbar'
        :checkbox-config='checkboxConfig'
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click='handleAdd' v-has="'rule:add'" type='primary'>新增</a-button>
            <a-dropdown v-if='selectedRowKeys.length > 0'>
              <a-menu slot='overlay'>
                <a-menu-item key='1' @click='batchDel'>
                  <a-icon type='delete' />
                  删除
                </a-menu-item>
              </a-menu>
              <a-button style='margin-left: 8px'> 批量操作
                <a-icon type='down' />
              </a-button>
            </a-dropdown>
          </div>
        </template>
        <template #detail='{ row:record }'>
          <a @click='handleDetail(record)'>{{ record.businessKey }}</a>
        </template>

        <template #action='{ row:record }'>
          <a @click='handleEdit(record)'>编辑</a>
          <a-divider type='vertical' />
          <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
            <a>删除</a>
          </a-popconfirm>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>

    <!-- 操作按钮区域 -->
    <div class='table-operator'>

    </div>
    <rule-code-modal ref='modalForm' @ok='modalFormOk'></rule-code-modal>
  </a-card>
</template>

<script>
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction } from '@api/manage'
import CnDictSelectTag from '@comp/dict/CnDictSelectTag'
import RuleCodeModal from '@page-modules/RuleCodeModal'

export default {
  name: 'ruleList',
  mixins: [PageListMixin],
  components: {
    RuleCodeModal,
    CnDictSelectTag,
  },
  data() {
    return {
      description: '编号规则',
      searchConfig: [
        {
          type: 'j-select',
          name: 'businessKey',
          dictCode: 'rule_key',
          placeholder: '业务标识'
        }],
      // 表头
      columns: [
        { type: 'checkbox', width: 50, fixed: 'left' },
        {
          title: '业务Key',
          minWidth: 100,
          field: 'businessKey',
          slots: { default: 'detail'}
        },
        {
          title: '业务规则',
          minWidth: 100,
          field: 'businessKey_dictText'
        },
        {
          title: '开始字符',
          minWidth: 100,
          field: 'startStr'
        },
        {
          title: '时间格式',
          minWidth: 100,
          field: 'timeStr'
        },
        {
          title: '结尾字符',
          minWidth: 100,
          field: 'endStr'
        },
        {
          title: '字符长度',
          minWidth: 100,
          field: 'codeLength'
        },
        {
          title: '递增数',
          minWidth: 100,
          field: 'increNum'
        },
        {
          title: '开始值',
          minWidth: 100,
          field: 'startVal'
        },
        {
          title: '当前值',
          minWidth: 100,
          field: 'nowVal'
        },
        {
          title: '创建人',
          field: 'createName',
          minWidth: 80,
        },
        {
          title: '创建时间',
          field: 'createTime',
          minWidth: 80,
        },
        {
          title: '更新人',
          field: 'updateName',
          minWidth: 80,
        },
        {
          title: '更新时间',
          field: 'updateTime',
          minWidth: 80,
        },
        {
          title: '操作',
          field: 'action',
          align: 'center',
          fixed: 'right',
          width: 120,
          slots: {
            default: 'action'
          }
        }
      ],
      url: {
        list: window._CONFIG['domianURL'] + '/cnCodeRuleController/findPageList',
        delete: window._CONFIG['domianURL'] + '/cnCodeRuleController/delete',
        exportXlsUrl: window._CONFIG['domianURL'] + 'cnCodeRuleController/exportXls'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {}
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>